package com.vue.admin.service.impl;

import com.vue.admin.entity.SysUser;
import com.vue.admin.entity.SysUserExample;
import com.vue.admin.mapper.SysUserMapper;
import com.vue.admin.service.SysUserService;
import com.vue.admin.util.StringUtil;
import com.vue.admin.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    public List<SysUser> selectByCondition(SysUserExample example) {
        List<SysUser> allItems = sysUserMapper.selectByExample(example);        //全部商品
        return allItems;
    }

    @Transactional

    public boolean save(SysUser sysUser) {
        if (StringUtil.isEmpty(sysUser.getId())) {
            sysUser.setCreateTime(new Date());
            sysUser.setId(UUIDUtil.uuidRandom());
            return sysUserMapper.insert(sysUser) > 0;
        } else {
            sysUser.setUpdateTime(new Date());
            return sysUserMapper.updateByPrimaryKey(sysUser) > 0;
        }
    }


    @Transactional
    public boolean delete(String id){
        return sysUserMapper.deleteByPrimaryKey(id) > 0;
    }
}
